package cj.web.activity.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import cj.web.activity.domain.Gift;
import cj.web.activity.domain.GiftSeller;
import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;

/**
 * 
 * @author 
 *
 */
@DAO
public interface GiftDAO{
	
	@SQL("SELECT * FROM Gift WHERE 1=1  AND name=:t.name, AND link=:t.link, AND imgURL=:t.imgURL, AND sellerId=:t.sellerId, AND orderId=:t.orderId, AND deleteFlag=:t.deleteFlag, AND createAT=:t.createAT, AND updateAT=:t.updateAT ORDER BY update_date DESC LIMIT :t.start,:t.end ")
    List<Gift> query(@SQLParam("t") Gift gift);
    
    @SQL("select * from Gift where id=:1")
    Gift queryById(String id);
    
    @SQL("INSERT INTO Gift(name,link,imgURL,sellerId,orderId,deleteFlag,createAT,updateAT) VALUES (:t.name,:t.link,:t.imgURL,:t.sellerId,:t.orderId,:t.deleteFlag,:t.createAT,:t.updateAT)")
    void create(@SQLParam("t") Gift gift);
	
	@SQL("UPDATE Gift SET name=:t.name,link=:t.link,imgURL=:t.imgURL,sellerId=:t.sellerId,orderId=:t.orderId,updateAT=:t.updateAT WHERE id=:t.id")
    void update(@SQLParam("t") Gift gift);
    
    @SQL("UPDATE Gift SET deleteFlag=0 WHERE id=:1")
    void deleteById(String id);
    
    @SQL("select a.id,a.name,a.link,a.imgURL,a.orderId,count(b.id) as click from Gift a LEFT JOIN LinkMsg b ON a.id = b.linkId where a.sellerId=:t.sellerId and a.deleteFlag=1 #if(:t.name!=''){ and name like '%##(:t.name)%'} group by a.id order by a.orderId limit :t.start, :t.length")
    List<Map> queryByName(@SQLParam("t")Gift gift);
    
    @SQL("select count(1) from Gift where sellerId=:t.sellerId and deleteFlag=1 #if(:t.name!=''){ and name like '%##(:t.name)%'}")
    int countByName(@SQLParam("t")Gift gift);
}